<!--
 * @Description:
 * @Author: william
 * @Date: 2023-11-28 16:54:11
 * @LastEditors: william
 * @LastEditTime: 2025-02-07 10:46:52
-->
<template>
  <div
    v-if="isExternal"
    :style="styleExternalIcon"
    class="svg-external-icon svg-icon"
    :="$attrs"
  />
  <svg v-else :class="svgClass" aria-hidden="true" :="$attrs">
    <use :href="iconName" />
  </svg>
</template>

<script setup>
const props = defineProps({
  iconClass: {
    type: String,
    required: true
  },
  className: {
    type: String,
    default: ''
  }
})

const isExternal = computed(() => g_utils.isExternal(props.iconClass))
const iconName = computed(() => `#icon-${props.iconClass}`)
const svgClass = computed(() => {
  return props.className ? 'svg-icon ' + props.className : 'svg-icon'
})
const styleExternalIcon = computed(() => ({
  mask: `url(${props.iconClass}) no-repeat 50% 50%`,
  '-webkit-mask': `url(${props.iconClass}) no-repeat 50% 50%`
}))
</script>

<style scoped>
.svg-icon {
  width: 18px;
  height: 18px;
  /* vertical-align: -0.15em; */
  fill: var(--color-666);
  overflow: hidden;
}

.svg-external-icon {
  background-color: var(--subtone-theme);
  mask-size: cover !important;
  display: inline-block;
}
</style>
